package com.watermark.ui;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * 权限申请抽象类
 */
public abstract class AbsPermissionActivity extends Activity {
    protected Activity activity;

    @Deprecated
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = this;
        if (PermissionUtil.checkPermissions(this, onCheckPermission())) {
            onPermissionAccept(true);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (PermissionUtil.REQUEST_CODE == requestCode) {
            String[] arr = PermissionUtil.getDeniedPermissions(permissions);
            boolean accept = null == arr || 0 == arr.length;
            onPermissionAccept(accept);
        }
    }

    /**
     * @return 设置检测权限的数组
     */
    protected abstract String[] onCheckPermission();

    /**
     * @param accept 是否接受权限
     */
    protected abstract void onPermissionAccept(boolean accept);
}